<template>
	<view class="orderItem">
		<view>{{tabledetail.tablenumber}}</view>
		<view class="orderItem-dishes">
			<view v-for="(item, index) in dishesData" :key="index">
				<!-- <image :src="item.imgurl"></image> -->
				<u-image :src="item.imgurl" width="125rpx" height="125rpx" :border-radius="10" :fade="true"
					style="margin-right: 20rpx">
					<u-loading slot="loading"></u-loading>
				</u-image>
				<view>
					<text>{{ item.name }}</text>
					<view>{{ item.type }}</view>
					<view>
						<text>￥</text>
						<text>{{ item.nowprice }}</text>
					</view>
				</view>
				<view>x {{ item.count }}</view>
				<view>
					<text>￥</text>
					<text>{{ item.nowprice * item.count }}</text>
				</view>
			</view>
		</view>
		<view class="person">用餐人数:{{tabledetail.personnum}}</view>
		<view class="person">餐位费:<text
				:style="((totalfee>=leastfee)&&leastfee>0)?'text-decoration: line-through;color:#dddddd':''">￥{{tabledetail.tablefee}}</text>
			<text v-if="leastfee>0&&totalfee>=leastfee">￥0</text>
		</view>
		<view class="person">就餐形式:<u-radio-group v-model="orederparam.type">
				<u-radio @change="radioChange" v-for="(item, index) in list" :key="index" :name="item.name"
					:disabled="item.disabled">
					{{item.name}}
				</u-radio>
			</u-radio-group>
		</view>
		<view v-if="orederparam.type =='预订'" class="person">用餐时间:{{orederparam.pretime}}</view>
		<view class="person">备注:
			<u-input v-model="orederparam.remark" :type="inputtype" :border="border" @blur="changeremark" />
		</view>
		<u-picker v-model="show" mode="time" :params="params" @confirm="confirmdate"></u-picker>
		<u-top-tips ref="uTips"></u-top-tips>
	</view>
</template>

<script>
	export default {
		props: {
			dishesData: "",
			tabledetail: "",
			totalfee: 0
		},
		data() {
			return {
				orederparam: {
					useraccount: '',
					remark: '',
					tablefee: 0,
					tablename: '',
					personnum: 0,
					type: '',
					pretime: '',
					price: '',
					dishlist: []
				},
				type: null,
				orderTime: '',
				currentyear: '',
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true,
					timestamp: true
				},
				show: false,
				typevalue: '',
				list: [{
						name: '实时就餐',
						disabled: false
					},
					{
						name: '预订',
						disabled: false
					}
				],
				remark: '',
				inputtype: 'text',
				border: true,
				leasefee: 0
			}
		},
		created() {
			let account = JSON.parse(uni.getStorageSync('currentUser')).account
			this.orederparam.personnum = this.tabledetail.personnum
			this.orederparam.tablename = this.tabledetail.tablenumber
			this.orederparam.useraccount = JSON.parse(uni.getStorageSync('currentUser')).account
			this.orederparam.dishlist = this.dishesData
			this.leastfee = JSON.parse(uni.getStorageSync(account+'tablerecords')).leastfee
			// this.leastfee = this.tabledetail.leastfee
			if ((this.leastfee > 0) && (this.totalfee >= this.leastfee)) {
				this.orederparam.tablefee = 0
			} else {
				this.orederparam.tablefee = this.tabledetail.tablefee
			}
		},
		mounted() {
			this.$emit('getinfo', this.orederparam)
		},
		methods: {
			changeremark() {
				this.$emit('getinfo', this.orederparam)
			},
			getdate(d) {
				return d.getFullYear() + '-' + ((d.getMonth() + 1) / 10 < 1 ? ('0' + (d.getMonth() + 1)) : d.getMonth()) +
					'-' + ((
						d.getDate() / 10) < 1 ? ('0' + d.getDate()) : d.getDate()) + ' ' + ((d.getHours() / 10) < 1 ? (
							'0' + d.getHours()) :
						d.getHours()) + ':' + (d.getMinutes() / 10 < 1 ? ('0' + d.getMinutes()) : d.getMinutes()) + ':' + (
						d.getSeconds() /
						10 < 1 ? ('0' + d.getSeconds()) : d.getSeconds())
			},
			getLocalTime(nS) {
				return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
			},
			confirmdate(val) {
				let forma = val.timestamp * 1000
				let now = new Date().getTime()
				if (forma <= now) {
					this.$refs.uTips.show({
						title: '预订日期不能早与或等于当前日期哦',
						type: 'error',
						duration: '2300'
					})
					return
				}
				this.orederparam.pretime = this.getdate(new Date(forma))
				this.$emit('getinfo', this.orederparam)
			},
			radioChange(val) {
				if (val == '实时就餐') {
					// this.orederparam.type=1
					this.orederparam.type = val
					this.$emit('getinfo', this.orederparam)
				} else {
					// this.type=0
					this.show = true
					this.orederparam.type = val
					this.$emit('getinfo', this.orederparam)
				}

			}
		}
	};
</script>

<style lang="scss">
	.person {
		background-color: #ffffff;
		margin-top: 20rpx;
		padding: 10rpx;
	}

	.orderItem {
		&>view:nth-child(1) {
			font-size: 36rpx;
			height: 75rpx;
			line-height: 75rpx;
			padding-left: 25rpx;
			border-bottom: 1rpx dashed #ccc;
			background-color: #ffffff;
		}
	}

	.orderItem-dishes {
		background-color: #ffffff;

		&>view {
			display: flex;
			padding: 25rpx;
			align-items: center;

			&>image {
				width: 125rpx;
				height: 125rpx;
				border-radius: 10rpx;
				background-color: red;
				margin-right: 20rpx;
			}

			&>view:nth-child(2) {
				font-size: 30rpx;

				&>view:nth-child(2) {
					font-size: 26rpx;
					color: #ccc;
					padding: 10rpx 0rpx;
				}

				&>view:nth-child(3) {
					color: red;

					text:nth-child(1) {
						font-size: 22rpx;
					}
				}
			}

			&>view:nth-child(3) {
				flex: 1;
				color: #ccc;
				text-align: right;
			}

			&>view:nth-child(4) {
				font-size: 32rpx;
				width: 140rpx;
				text-align: right;
			}
		}
	}
</style>
